package br.ufc.customJDBC.csv;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

public class CSVLog {
	
	private BufferedWriter bw;	
	
	public CSVLog(String pathname){ 
		try {
			File file = new File(pathname);
			if (!file.exists()) {
				file.createNewFile();
			}
			bw = new BufferedWriter(new FileWriter(file));
		} catch (IOException e) {
			e.printStackTrace();
		}

		System.out.println(pathname);
	}
	
	public void writeLine(String sql, Long responseTime, int numberOfRows, String function, String ip, int vms){
		try {	
			bw.write(ip + " ;; " + System.currentTimeMillis() + " ;; " +numberOfRows+" ;; "+responseTime+" ;; "+ function + " ;; " +sql + " ;; " + vms +"\n");
		} catch (IOException e) {
			e.printStackTrace();
		}		
	}
	
	public void writeLine(String sql, Long responseTime, int numberOfRows, String function, String ip){
		try {	
			bw.write(ip + " ;; " + System.currentTimeMillis() + " ;; " +numberOfRows+" ;; "+responseTime+" ;; "+ function + " ;; " +sql+"\n");
		} catch (IOException e) {
			e.printStackTrace();
		}		
	}

	public void close() {
		try {
			bw.flush();
			bw.close();
		} catch (IOException e) {
			e.printStackTrace();
		}		
	}
}
